// 请求默认配置
import _ from '@/utils/commonFn';

export const requestConfig = {
  timeout: 5000,
  baseURL: '/api',
  transformRequest: [
    (data, header) => {
      const params = new URLSearchParams();
      header['Content-Type'] = 'application/x-www-form-urlencoded';

      if (_.isPlainObject(data)) {
        Object.entries(data).forEach(([key, val]) => {
          if (Array.isArray(val)) {
            val.forEach((item) => {
              params.append(key, item);
            });
          } else {
            params.append(key, val);
          }
        });
      }
      return params;
    }
  ]
};
